package com.car.service.send;

import javax.annotation.Resource;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.Session;
import javax.jms.TextMessage;

import org.apache.activemq.ScheduledMessage;
import org.apache.activemq.command.ActiveMQTextMessage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.core.JmsMessagingTemplate;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.jms.core.MessageCreator;
import org.springframework.stereotype.Service;

import com.car.util.Fianl;

@Service
public class OrderTimeoutProducer {
	@Autowired
	private JmsTemplate jmsTemplate;
	
	
	
	public void sendMessage( String msg,final Long timeout){
		jmsTemplate.send("orderTimeout",new MessageCreator() {
			@Override
			public Message createMessage(Session session) throws JMSException {
				// TODO Auto-generated method stub
				TextMessage message = session.createTextMessage(msg);
				message.setLongProperty(ScheduledMessage.AMQ_SCHEDULED_DELAY, timeout);
				return message;
			}
		});
	}
	
	public void sendMessage( String msg){
		
		this.sendMessage(msg, Fianl.ORDER_TIMEOUT);
	}

}
